// pages/my/userInfo/userInfo.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        avatarUrl: '/images/my/tx.png',
        nickName: '',
        theme: '',
        introduce: '还没发表介绍~'
    },

    bindinputintroduce(e) {
        this.setData({
            introduce: e.detail.value
        })
    },

    onChooseAvatar(e) {
        const {
            avatarUrl
        } = e.detail
        this.setData({
            avatarUrl,
        })
        console.log('avatarUrl', avatarUrl);
        // app.globalData.userInfo.avatarUrl = avatarUrl
    },

    formSubmit(e) {
        // app.globalData.userInfo.nickName = e.detail.value.nickname;
        console.log('e.detail.value.nickname', e.detail.value.nickname);
        const name = e.detail.value.nickname;
        if (name) {
            this.setData({
                nickName: name,
            })
        }
        wx.showLoading()
        const userinfo = wx.getStorageSync('userinfo')
        userinfo.avatar = this.data.avatarUrl
        userinfo.nickname = this.data.nickName
        userinfo.introduce = this.data.introduce;
        console.log('保存信息userinfo:', userinfo);
        wx.setStorageSync('userinfo', userinfo)
        const myset = setTimeout(() => {
            wx.navigateBack();
            wx.hideLoading()
            clearTimeout(myset)
        }, 1000)
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        const userinfo = wx.getStorageSync('userinfo');
        this.setData({
            avatarUrl: userinfo.avatar,
            nickname: userinfo.nickname,
            introduce: userinfo.introduce
        })
        wx.onThemeChange((result) => {
            console.log('onThemeChange', result.theme)
            this.setData({
                theme: result.theme
            })
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})